package com.miaosha;

import java.util.Date;
import org.apache.http.client.methods.HttpGet;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.utils.DateUtil;

/**
 * 秒杀任务创建
 * @author TANGJZ2
 *
 */
public class MiaoShaJob implements Job{
	public static Logger logger = Logger.getLogger(MiaoShaJob.class);
	public static String[] params;
	
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		logger.info("秒杀程序启动");
		try {
			Date startTime = DateUtil.parse(DateUtil.format(new Date(), "yyyy-MM-dd") + " " + params[2], "yyyy-MM-dd HH:mm:ss.S");
			MediaService.login(params[0], params[1]);
			MediaService.sign();
			String couponId = MediaService.getCouponId();
			HttpGet httpGet = new HttpGet(MediaService.MIAOSHA_URL + couponId);
			MediaService.createSchedule(startTime, httpGet);
		} catch (Exception e) {
			logger.error("秒杀失败", e);
		}
	}

}
